<template>
  <div class="login">
    <el-form ref="loginForm" :model="loginForm" :rules="loginRules" class="login-form">
      <h3 class="title">代码生成工具</h3>
      <el-form-item prop="username">
        <el-input v-model="loginForm.username" type="text" auto-complete="off" autofocus placeholder="账号"
                  @keyup.enter.native="handleLogin">
          <svg-icon slot="prefix" icon-class="user" class="el-input__icon input-icon"/>
        </el-input>
      </el-form-item>
      <el-form-item prop="password">
        <el-input v-model="loginForm.password" type="password" auto-complete="off" placeholder="密码"
                  @keyup.enter.native="handleLogin">
          <svg-icon slot="prefix" icon-class="password" class="el-input__icon input-icon"/>
        </el-input>
      </el-form-item>
      <el-form-item style="width: 100%">
        <el-button :loading="loading" size="medium" type="primary" style="width: 100%"
                   @click.native.prevent="handleLogin">
          <span v-if="!loading">登 录</span>
          <span v-else>登 录 中...</span>
        </el-button>
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
export default {
  name: "login",
  data() {
    return {
      loginForm: {
        username: '',
        password: '',
      },
      loginRules: {
        username: [{required: true, trigger: 'blur', message: '请输入您的账号'}],
        password: [{required: true, trigger: 'blur', message: '请输入您的密码'}],
      },
      loading: false,
      redirect: undefined,
      //验证码输入框是否聚焦
      isfocus: true,
    };
  },
  methods: {
    handleLogin() {
      this.$refs.loginForm.validate((valid) => {
        if (valid) {
          if (this.loginForm.username === 'qmf' && this.loginForm.password === 'test') {
            this.loading = true;
            window.sessionStorage.setItem('token', 'asdhoiqnwocznxoch0982357039aus0d0a' + new Date().getTime())
            this.$router.push('/dashboard')
          } else {
            this.tip('用户名或密码错误', 'error')
          }
        }
      });
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss">
.login {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  background-size: cover;
  background-color: black;
}

.title {
  margin: 0px auto 30px auto;
  text-align: center;
  color: #fff;
  z-index: 1000;
}

.login-form {
  border-radius: 6px;
  background: rgba(6, 23, 46, 0.8);
  width: 400px;
  padding: 25px 25px 5px 25px;
  z-index: 2001;

  .el-input {
    height: 38px;
    z-index: 1000;

    input {
      z-index: 1000;
      height: 38px;
    }
  }

  .input-icon {
    height: 39px;
    width: 14px;
    margin-left: 2px;
    z-index: 1000;
  }
}
</style>
